package com.exam.microsoft;

import java.util.*;

/**
 * date:
 * description:
 */
public class Solution003 {
    public static void main(String[] args) {
        //double x = 1.0 / 3.0;
        //double y = 2.0 / 3.0;
        //System.out.println(x == 1 - y);
        //System.out.println(Integer.MAX_VALUE);
        int[] X = {1, 2, 3, 1, 2, 12, 8, 4};
        int[] Y = {5, 10, 15, 2, 4, 15, 10, 5};
        //int[] X = {1, 1, 2};
        //int[] Y = {3, 2, 3};
        Solution003 instance = new Solution003();
        int res = instance.solution(X, Y);
        System.out.println(res);
    }

    public int solution(int[] X, int[] Y) {
        HashMap<Double, Integer> map = new HashMap<>();
        int len = X.length;
        for (int i = 0; i < len; i++) {
            double num = ((double) X[i]) / ((double) Y[i]);
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        Set<Double> keySet = map.keySet();
        ArrayList<Double> list = new ArrayList<>(keySet);
        Collections.sort(list);
        long res = 0L;
        long modulo = (long) 1e9 + 7;
        for (int i = 0; i < list.size(); i++) {
            double cur = list.get(i);
            if(cur > 0.5){
                break;
            }
            int n = map.get(cur);
            if(cur == 0.5){
                res += ((long) n * (long) (n - 1) / 2) % modulo;
                res %= modulo;
                break;
            }
            for (int j = list.size() - 1; j > i; j--) {
                double candidate = list.get(j);
                if(candidate + cur < 1){
                    break;
                } else if(candidate + cur == 1){
                    int pairNum = map.get(candidate);
                    res += ((long) n * (long) pairNum) % modulo;
                    res %= modulo;
                }
            }
        }
        return (int) res;
        // write your code in Java 8 (Java SE 8)
    }
}
